# -*- coding: utf-8 -*-
from venv1.Page.policyIfmComPage import policyIfmComPage
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import xlrd
class policyIfmCom():
    def __init__(self,driver):
        self.driver=driver
        self.policyIfmComPage=policyIfmComPage(self.driver)
    def PolicyIfm_comfire(self,PolicyNo):
        # 點擊保單信息確認
        self.policyIfmComPage.btnPolicyIfmCom().click()
        time.sleep(1)
        # 輸入保單號
        self.policyIfmComPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        # 任務獲取
        self.policyIfmComPage.btnPolicyGet().click()
        time.sleep(1)
        # 切換窗口
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        # 點擊彈框確認按鈕
        self.policyIfmComPage.btnSubmit().click()
        time.sleep(1)
        # 切換窗口
        window2 = self.driver.window_handles
        self.driver.switch_to.window(window2[-1])
        time.sleep(1)
        # 選擇目標數據
        self.policyIfmComPage.TargetData().click()
        time.sleep(1)
        # 打印窗口句柄
        print(self.driver.window_handles)
        # 關閉標籤頁
        ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('W').key_up(Keys.CONTROL).perform()
        time.sleep(1)
        try:
            window3 = self.driver.window_handles
            self.driver.switch_to.window(window3[2])
            time.sleep(3)
        except Exception as msg:
            print('error:',msg)
        # print(self.driver.current_window_handle)
        # time.sleep(2)
        # self.driver.close()
        # 點擊通過
        window4 = self.driver.window_handles
        self.driver.switch_to.window(window4[-1])
        time.sleep(1)
        self.policyIfmComPage.btnPass().click()
        time.sleep(1)
        # 點擊確認
        # window5 = self.driver.window_handles
        # self.driver.switch_to.window(window5[-1])
        # time.sleep(1)
        self.policyIfmComPage.btnSubmit().click()
        time.sleep(1)
    def drop(self,PolicyNo,ProjectCode):
        # 點擊保單信息確認
        self.policyIfmComPage.btnPolicyIfmCom().click()
        time.sleep(1)
        # 輸入保單號
        self.policyIfmComPage.inpPolicyNo().send_keys(PolicyNo)
        time.sleep(1)
        # 任務獲取
        self.policyIfmComPage.btnPolicyGet().click()
        time.sleep(1)
        # 切換窗口
        window1 = self.driver.window_handles
        self.driver.switch_to.window(window1[-1])
        time.sleep(1)
        # 點擊彈框確認按鈕
        self.policyIfmComPage.btnSubmit().click()
        time.sleep(1)
        # 切換窗口
        window2 = self.driver.window_handles
        self.driver.switch_to.window(window2[-1])
        time.sleep(1)
        # 選擇目標數據
        self.policyIfmComPage.TargetData().click()
        time.sleep(1)
        # 關閉標籤頁
        ActionChains(self.driver).key_down(Keys.CONTROL).send_keys('W').key_up(Keys.CONTROL).perform()
        time.sleep(1)
        window4 = self.driver.window_handles
        self.driver.switch_to.window(window4[-1])
        time.sleep(1)
        # 添加问题件
        self.policyIfmComPage.btnAdd_project().click()
        time.sleep(1)
        # 填写问题件代码
        self.policyIfmComPage.inpProjectCode().send_keys(ProjectCode)
        time.sleep(1)
        self.policyIfmComPage.inpProjectCode().click()
        time.sleep(1)
        # 选择问题件
        self.policyIfmComPage.secProjectCode().click()
        time.sleep(1)
        self.policyIfmComPage.btnPass().click()
        time.sleep(1)
        # 點擊確認
        # window5 = self.driver.window_handles
        # self.driver.switch_to.window(window5[-1])
        # time.sleep(1)
        self.policyIfmComPage.btnSubmit2().click()
        time.sleep(1)









